<template>
  <a-modal
    title="请选择复核人"
    :visible="showApproveConfirm"
    :confirm-loading="confirmLoading"
    ok-text="确认提交复核"
    @ok="submitApprove"
    @cancel="approveCancel"
  >
    <a-select
      show-search
      placeholder="请选择复核人"
      option-filter-prop="children"
      style="width: 200px"
      title="请选择复核人"
      v-model="approverId"
    >
      <a-select-option v-for="(item, index) in approverList" :key="item.userId" :value="item.userId">
        {{ item.userName }}
      </a-select-option>
    </a-select>
  </a-modal>
</template>

<script>
import { getAction } from '@api/manage'
import store from '@/store'

export default {
  name: 'SelectQzApprover',
  props: ['id'],
  components: {},
  data() {
    return {
      approverList: [], //审批人列表
      confirmLoading: false,
      showApproveConfirm: false,
      approverId: null,
      url: {
        getApprover: '/sjxmzygl/sjWorkZtfaEvidence/queryMemberByProId'
      }
    }
  },
  created() {
    // this.showApproverModal()
  },
  computed: {
    uploadAction: function() {
      return this.url.fileUpload
    }
  },
  methods: {
    submitApprove() {
      if (this.approverId == null) {
        this.$message.error('请选择复核人')
      } else {
        this.$emit('submitData', this.approverId)
        this.showApproveConfirm = false
      }
    },
    approveCancel(e) {
      this.showApproveConfirm = false
    },
    /*selectApprover(val) {
      this.approverId = val
    },*/
    show() {
      this.showApproveConfirm = true
      this.showApproverModal()
    },
    //提交审批选择审批人并确认弹窗
    showApproverModal() {
      getAction(this.url.getApprover, { proId: this.id }).then((res) => {
        //获取审核人列表
        if (res.success && res.result && res.result.length > 0) {
          this.approverList = res.result
          let approverList = this.approverList.filter((item) => item.roleName == '主审')
          this.approverId = approverList.length > 0 ? approverList[0].userId : this.approverList[0].userId
        } else {
          this.$message.error("未查询到复核人")
          this.showApproveConfirm = false
        }
      })
    }
  }
}
</script>

<style scoped>
</style>
